package com.sofoscorp.android.gestcobranzamobile;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class TVTA_BO {
	private String gv_tabName = "TVTA";
	private ConexionDB go_conexDB;
	private Cursor gc_TVTA;
	private SQLiteDatabase go_db;
	
	private TVTA_Str gs_TVTA = null;
	String[] gt_campos = new String[]{"KUNNR", "BUKRS", "VKORG", "KKBER","WAERS"};
	
	public TVTA_BO(){
		go_conexDB = new ConexionDB();
	}
	
	public TVTA_Str get_SingleByKey(String ivBUKRS, String ivKUNNR){
		String lv_Where = "BUKRS = ? AND KUNNR = ?";
		String[] lt_WhereArgs;
		
		if((ivBUKRS.equals("") || ivBUKRS.equals(null)) && 
		   (ivKUNNR.equals("") || ivKUNNR.equals(null))){
			gs_TVTA = null;
		}else {
			gc_TVTA = null;
			lt_WhereArgs = new String[]{ivBUKRS, ivKUNNR};
			
			//Pasar el Path de DB
			go_conexDB.serialization(go_conexDB.C_PATH_FROMSAP);

			//Verificar si existe conexion con la DB
			if (go_conexDB.checkConexDB()) {

				//Obtener la DB
				go_db = go_conexDB.getGo_DB();
				
				try {
					//Ejecutar Select a la DB
					gc_TVTA = go_db.query(gv_tabName, gt_campos, lv_Where, lt_WhereArgs, null, null, null, null);
					if (gc_TVTA.moveToFirst()) {
						gs_TVTA = new TVTA_Str(	gc_TVTA.getString(0), 
											 	gc_TVTA.getString(1), 
											 	gc_TVTA.getString(2), 
											 	gc_TVTA.getString(3), 
											 	gc_TVTA.getString(4));
					}else{
						gs_TVTA = null;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
			}else{
				gs_TVTA = null;
			}
		}

		go_db.close();
		gc_TVTA.close();
		return gs_TVTA;
	}
}
